home *** CD-ROM | disk | FTP | other *** search
- Visual Basic and C Advanced File Function Library.
- Ver 0.2 12/30/91
-
- *--------------------------------------------------------------------------*
-
- This library was primarily written for use with Visual Basic, although C
- programmers may use it just as easily. Although these functions could be
- done is pure Visual Basic, this library greatly increases the speed of the
- functions.
- Compression is achieved using the LZH algorithm. Although somewhat slower
- than implode, it can obtain much better compression than implode. (Implode
- is the main compression used by ZIP.) Compression is dependent on the
- amount of repetition in a file. If a file contains a large amount of the
- same values of data, compression should be very good. Text and pictures with
- relatively large areas of a single color are good examples. Conversely, a
- .COM file, usually very compact and not very repetious, are usually poorly
- compressed, sometimes by an insignificant amount. The tradeoff for the
- amount of compression achieved by the LZH algorithm is speed. It can take
- a while to compress a large file.
-
- Library code was written for Microsoft C 6.00A. Data space consists of
- about 200 bytes. The data used for compression and decompression is
- dynamically allocated from the global heap. This means the calling program
- does not have to have a bloated data space and the data are may be marked
- as shared. Some code was written in assembler to prevent linking the
- standard C library, bloating the initial code segment to nearly 1000 bytes.
- As it stands, about 300 bytes in initially loaded, the rest only when called.
-
- This library is free to use by one and all AS LONG AS you agree not to
- hold me liable for and damage to hardware, software, firmware or your
- mental health by using this software. By using the library, the agreement is
- made. Otherwise, I would suggest you throw it away and pretend it never
- existed.
-
- Questions and suggestions made be made to me through the following by
- way of America Online, E-Mail to MarkG85.
-
- *--------------------------------------------------------------------------*
-
- This version corrects a bug in the DeleteFile() function where the DS
- and DX register contents were reversed during an error condition. In
- addition, a simple Visual Basic program serves as an example of how to use
- the library in that environment.
-
- *--------------------------------------------------------------------------*
-
- WLZHCXP.DLL is a Dynamic Linked Library (DLL) which provides additional
- functionality to a number of languages at very little cost to the program
- itself. GDI.EXE, USER.EXE and KRNL386.EXE are other examples of DLL files.
- To access this library, or any other, from Visual Basic, you must define
- the function names and the type of variables they expect to recieve and
- return. If the function definitions are incorrect, you are cheerfully told
- so by the smiling face of a UAE. Below are the definitions of functions
- available from this library and the types of variables they expect and
- return. Variables ending with a percent (%) sign are integers, those ending
- with an ampersand (&) are long integers and those ending in a dollar sign
- ($) are strings. A number of variables are filenames and thus require a
- string to be passed such as filename$ or "filename.ext". For more infor-
- -mation, see the Visual Basic example provided. And speaking of which...
-
- Examples are not my strong point and this one is no exception. To use
- the program, start by copying this file, WLZHCXP.TXT to your Visual Basic
- directory and press the "Compress" button which creates the file for the
- "Decompress" function. Next, run "Decompress" which creates the file for
- "Append", "Copy" and "Delete". After "Delete", you must again either "Copy"
- or "Decompress" to create the file WLZHCXP.OUT. Programming is straight-
- -forward and commented enough to figure out what's happening.
-
- *--------------------------------------------------------------------------*
-
- To use the library from Visual Basic, you must define the return constants
- and functions in your Global Module as such:
-
- Global Const LZH_OK = 0
- Global Const LZH_MEMERROR = 1
- Global Const LZH_NOTLZH = 2
- Global Const LZH_FILEERROR = 3
-
- Global Const LZH_READONLY = 1
- Global Const LZH_HIDDEN = 2
- GLobal Const LZH_SYSTEM = 4
-
- Declare Function Compress% LIB "wlzhcxp.dll" (ByVal InName$,ByVal OutName$)
- Declare Function Decompress% LIB "wlzhcxp.dll" (ByVal InName$,ByVal OutName$)
- Declare Function AppendFile% LIB "wlzhcxp.dll" (ByVal Dest$,ByVal File2$)
- Declare Function DeleteFile% LIB "wlzhcxp.dll" (ByVal Fname$)
- Declare Function GetFileSize& LIB "wlzhcxp.dll" (ByVal Fname$)
- Declare Function CopyFile% LIB "wlzhcxp.dll" (ByVal Srce$,ByVal Dest$)
- Declare Function GetFreeDiskSpace& LIB "wlzhcxp.dll" (ByVal Drv$)
- Declare Function SetFileStatus% LIB "wlzhcxp.dll" (ByVal Fname$, ByVal Status% )
-
- *--------------------------------------------------------------------------*
-
- Using the library from C is considerably more flexible. For the sake of
- and example, I'll use the automatic runtime linking method:
-
- * SOURCE.H:
-
- #define LZH_OK 0
- #define LZH_MEMERROR 1
- #define LZH_NOTLZH 2
- #define LZH_FILEERROR 3
-
- int FAR PASCAL Compress( LPSTR, LPSTR );
- int FAR PASCAL Decompress( LPSTR, LPSTR );
- int FAR PASCAL AppendFile( LPSTR, LPSTR );
- int FAR PASCAL DeleteFile( LPSTR );
- long FAR PASCAL GetFileSize( LPSTR );
- int FAR PASCAL CopyFile( LPSTR, LPSTR );
-
-
- * SOURCE.DEF
-
- IMPORTS
- Compress=WLZHCXP.2
- Decompress=WLZHCXP.3
- AppendFile=WLZHCXP.5
- DeleteFile=WLZHCXP.6
- GetFileSize=WLZHCXP.4
- CopyFile=WLZHCXP.7
- GetFreeDiskSpace=WLZHCXP.8
-
- * SOURCE.MAK
-
- link /NOD SOURCE,,,SOURCE.EXE,MLIBCEW LIBW WLZHCXP,SOURCE.DEF
-
- Note that the library was compiled and linked using the MEDIUM memory model.
-
- *--------------------------------------------------------------------------*
-
- Error codes:
- LZH_OK: Everything went OK, no errors.
- LZH_MEMERROR: A memory error occurred. Unable to continue operation.
- LZH_NOTLZH: File to be decompressed was not compressed.
- LZH_FILEERROR: A file error occurred. Unable to continue operation.
-
- *--------------------------------------------------------------------------*
-
- Function listing:
-
-
- int FAR PASCAL Compress( LPSTR InName, LPSTR OutName )
- Compresses data taken from source file, writing results to destination.
-
- Parameters:
- InName: Filename of source file to be compressed.
- OutName: Filename of destination file to hold compressed data.
-
- Returns:
- LZH_OK if no errors or error code listed above.
-
- *--------------------------------------------------------------------------*
-
- int FAR PASCAL Decompress( LPSTR InName, LPSTR OutName )
- Decompresses data from source file, writing results to destination.
-
- Parameters:
- InName: Filename of source file containing compressed data.
- OutName: Filename of destination file to receive decompressed data.
-
- Returns:
- LZH_OK if no errors or error code listed above.
-
- *--------------------------------------------------------------------------*
-
- int FAR PASCAL AppendFile( LPSTR lpTarget, LPSTR lpFile2 )
- Adds a file to the back of another file.
-
- Parameters:
- lpTarget: First source filename. This file receives the second file.
- lpFile2: Second source filename. This is added to the first file.
-
- Returns:
- LZH_OK if no errors or error code listed above.
-
- Notes:
- lpTarget MUST be a valid file. If the filename specified is not found,
- it is NOT created. The second file specified is added the end of the
- first, but is not deleted.
-
- *--------------------------------------------------------------------------*
-
- int FAR PASCAL DeleteFile( LPSTR Filename )
- Deletes file(s) specified by filename. You may use wildcard characters.
-
- Parameters:
- Filename: Name of the file to be deleted from disk.
-
- Returns:
- LZH_OK if no errors or error code listed above.
-
- *--------------------------------------------------------------------------*
-
- long FAR PASCAL GetFileSize( LPSTR Filename )
- Obtains the byte size of a file.
-
- Parameters:
- Filename: Name of file to find the size of.
-
- Returns:
- 0 if file not found or file size as a 4 byte long value.
-
- *--------------------------------------------------------------------------*
-
- int FAR PASCAL CopyFile( LPSTR Source, LPSTR Dest )
- Copies a source file to a destination file.
-
- Parameters:
- Source: Filename of fie to be copied.
- Dest: Filename to be created and copied to.
-
- Returns:
- LZH_OK if no errors or error code listed above.
-
- Notes:
- The source file is NOT deleted.
-
- *--------------------------------------------------------------------------*
-
- DWORD FAR PASCAL GetFreeDiskSpace( LPSTR lpDrv )
- Finds the amount of free disk space in bytes.
-
- Parameters:
- lpDrv: NULL terminated string containing drive letter to check.
-
- Returns:
- 0 if an error occurred or bytes free on given disk.
-
- Notes:
- Only the first character in the string is actually worked on. The rest
- of the string is ignored. To obtain the size of the default (current)
- disk, make the first character ASCII 64.
-
- *--------------------------------------------------------------------------*
-
- int FAR PASCAL SetFileStatus( LPSTR Filename, int Status )
- Sets status of file.
-
- Parameters:
- Filename: Name of file to change the status of.
- Status: Attribute bits. Use LZH constants listed above.
-
- Returns:
- LZH_OK if no errors or error code listed above.
-
- Notes:
- Attribute constants are LZH_READONLY, LZH_HIDDEN and LZH_SYSTEM.
-
-
-